#!/bin/sh
# define variables
PROJECT_ROOT="/home/djdev/workspace/five"
DEPLOY_DIR="/var/www/djapi"
RESIN_HOME="/opt/resin-4.0.44/"
RESIN_LOG_FILE=$RESIN_HOME"log/jvm-app-0.log"
RESIN_LOG_BACKUP=$RESIN_HOME"log/jvm-app-`date`.log"

# stop resin server
echo "Stopping resin, using RESIN_HOME=$RESIN_HOME"
$RESIN_HOME/bin/resin.sh stop

# cleanup the previous log
echo "Backup and cleanup the log file"
cat $RESIN_LOG_FILE>>$RESIN_LOG_BACKUP
echo "">$RESIN_LOG_FILE

# cleanup
echo "Cleaning deployed package, DEPLOY_DIR=$DEPLOY_DIR"
rm -rf $DEPLOY_DIR/*

# compile and package
echo "Call maven build"
mvn clean package -DskipTests=true -Pprod

# wait
sleep 3

# unpack the war
echo "Unpackaging war file to $DEPLOY_DIR"
unzip $PROJECT_ROOT/packaging/target/DJ-API.war -d $DEPLOY_DIR

# start resin
echo "Starting resin..."
$RESIN_HOME/bin/resin.sh start
